package com.eascs.admin.oldO2olike.controller;

import java.io.IOException;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.common.utils.StringUtils;
import com.eascs.admin.o2o.backfee.service.O2OComBankFeeService;
import com.eascs.admin.o2o.credit.entity.CreditReport;
import com.eascs.admin.o2o.credit.service.CreditReportService;
import com.eascs.admin.o2o.detail.form.ShowDetailForm;
import com.eascs.admin.o2o.detail.service.LoanDetailService;
import com.eascs.admin.o2o.enterpriseZX.entity.O2oEnterpriseZxEntity;
import com.eascs.admin.o2o.enterpriseZX.service.O2oEnterpriseZxService;
import com.eascs.admin.o2o.internal.service.LoanapplyExpandService;
import com.eascs.admin.o2o.internal.util.BaseUtils;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.admin.o2o.o2ozx.serviceimpl.O2oLoadUserZxServiceImpl;
import com.eascs.admin.o2o.specialInterview.entity.O2OSpecialInterview;
import com.eascs.admin.o2o.specialInterview.service.O2OSpecialInterviewService;
import com.eascs.admin.o2o.zx.entity.O2oLoanUserEntityZx;
import com.eascs.admin.oldO2olike.form.OldO2oLikeForm;
import com.eascs.admin.oldO2olike.service.OldO2oLikeService;
import com.eascs.afterloan.service.AdvanceSettleService;
import com.eascs.afterloancheck.service.LoanCheckServicce;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.brand.service.O2oBrandService;
import com.eascs.brand.service.O2oPartnerService;
import com.eascs.brand.vo.BrandAndPartnerVo;
import com.eascs.common.doc.excel.DefaultRowWriteHandler;
import com.eascs.common.doc.excel.ExcelApiHelper;
import com.eascs.common.exception.RuntimeIOException;
import com.eascs.common.util.StringUtil;
import com.eascs.crm.common.service.ICustomerInfoService;
import com.eascs.loan.entity.O2oBankLoanData;
import com.eascs.loan.service.O2oLoanService;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;
import com.eascs.workflow.common.service.wf.WorkFlowService;
import com.eascs.workflow.common.type.SystemModule;

/**
 * 
 * @author  像老系统那样分开 显示
 *
 */
@Controller
@RequestMapping("/oldo2olike")
public class OldO2oLikeController extends BaseMasterViewController {
	
	private final Logger logger = LoggerFactory.getLogger(O2OComBankFeeService.class);
	
	@Autowired
	private OldO2oLikeService OldO2oLikeService;
	@Reference
	private WorkFlowService workFlowService;
	@Reference
	private ICustomerInfoService iCustomerInfoService;
	@Autowired
	private O2oPartnerService o2oPartnerService;
	
	@Autowired
	private O2oLoanapplyService o2oloanapplyService;
	@Autowired
	private CreditReportService creditReportService;
	@Autowired
	private O2oLoanUserService o2oLoanUserService;
	@Autowired
	private LoanapplyExpandService loanapplyExpandService;
	@Autowired
	private O2oLoanService o2oLoanService;
	@Autowired
	private O2oBrandService o2oBrandService;
	@Value("${o2o.admin.iframe.domain}")
	private String domain;
	@Autowired
	LoanCheckServicce loanCheckServicce;
	@Autowired
	private LoanDetailService loanDetailService;
	@Autowired
	AdvanceSettleService advanceSettleService;
	@Autowired
	private BaseUtils baseUtils;
	@Autowired
	private O2oEnterpriseZxService o2oEnterpriseZxService;
	@Autowired
	O2OSpecialInterviewService o2OSpecialInterviewService;
	
	@Autowired
	private O2oLoadUserZxServiceImpl o2oLoadUserZxServiceImpl;
	@Value("${oa.O2OstampUseRequestSavePre.url}")
	private String O2OstampUseRequestSavePre;
	@Reference
	SysOrgService sysOrgService;


	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "QueryLoadMenu");
	}

	
	@RequestMapping(value="/zx",method=RequestMethod.GET)
	public String search(OldO2oLikeForm oldO2oLikeForm) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "zx_liebiao");
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		ViewContext.put("ActOrgEntitys", orgProvince);
		oldO2oLikeForm.setPageSize(BaseUtils.PAGE_SIZE);
		List<User> users=sysOrgService.checkDataPermission(UserHolder.getUser().getNo());
		String no="";
		if (users!=null) {
			for (User user : users) {
				no+=user.getNo()+",";
			}
		}
		if (!"".equals(no)) {
			if (",".equals(no.substring(no.length()-1, no.length()))) {
				no=no.substring(0, no.length()-1);
			}
		}
		logger.info("userno={}", no);
		
		oldO2oLikeForm.setPartnerId(no);
		
		PageResult<Object[]> pageResult = OldO2oLikeService.findZXByPage(oldO2oLikeForm,null);
		String[] titles = {"贷款单号", "征信银行", "借款人姓名", "信贷经理", "经营平台","省区", "贷款类型","申请状态", "单据状态", "申请金额(万元)",
			"创建时间","提交时间","结束时间" };
		SelectDataOption[] selectDataOptions = {null, new SelectDataOption("BANKTYPEO2O"),  null, null,null,null, new SelectDataOption("OTO_LOAN_TYPE"),
				new SelectDataOption("SQZT"),new SelectDataOption("LCZT"), null, null , null , null 
				};
		StringBuffer pageUrl=new StringBuffer("/oldo2olike/zx");
		StringBuffer reporto2ourl = new StringBuffer("/oldo2olike/zx/download");
		if(oldO2oLikeForm!=null){
			String billCode=oldO2oLikeForm.getBillCode()==null?"":oldO2oLikeForm.getBillCode();
			String billStatus=oldO2oLikeForm.getBillStatus()==null?"":oldO2oLikeForm.getBillStatus();
			String loadName=oldO2oLikeForm.getLoadName()==null?"":oldO2oLikeForm.getLoadName();
			String userSurname=oldO2oLikeForm.getUserSurname()==null?"":oldO2oLikeForm.getUserSurname();
			String operatorName=oldO2oLikeForm.getOperatorName()==null?"":oldO2oLikeForm.getOperatorName();
			String loanType=oldO2oLikeForm.getLoanType()==null?"":oldO2oLikeForm.getLoanType();
			String startTime=oldO2oLikeForm.getStartTime()==null?"":oldO2oLikeForm.getStartTime();
			String endTime=oldO2oLikeForm.getEndTime()==null?"":oldO2oLikeForm.getEndTime();
			String stTime=oldO2oLikeForm.getStTime()==null?"":oldO2oLikeForm.getStTime();
			String sendTime=oldO2oLikeForm.getSendTime()==null?"":oldO2oLikeForm.getSendTime();
			String eendTime=oldO2oLikeForm.getEendTime()==null?"":oldO2oLikeForm.getEendTime();
			String eendendTime=oldO2oLikeForm.getEendendTime()==null?"":oldO2oLikeForm.getEendendTime();
			String hostProvince=oldO2oLikeForm.getHostProvince()==null?"":oldO2oLikeForm.getHostProvince();
			String payMentStatus=oldO2oLikeForm.getPayMentStatus()==null?"":oldO2oLikeForm.getPayMentStatus();
			
			pageUrl.append("?billCode="+billCode);
			pageUrl.append("&loadName="+loadName);
			pageUrl.append("&userSurname="+userSurname);
			pageUrl.append("&operatorName="+operatorName);
			pageUrl.append("&loanType="+loanType);
			pageUrl.append("&startTime="+startTime);
			pageUrl.append("&endTime="+endTime);
			pageUrl.append("&stTime="+stTime);
			pageUrl.append("&sendTime="+sendTime);
			pageUrl.append("&eendTime="+eendTime);
			pageUrl.append("&eendendTime="+eendendTime);
			pageUrl.append("&hostProvince="+hostProvince);
			pageUrl.append("&billStatus="+billStatus);
			pageUrl.append("&payMentStatus="+payMentStatus);
			
			reporto2ourl.append("?billCode="+billCode);
			reporto2ourl.append("&loadName="+loadName);
			reporto2ourl.append("&userSurname="+userSurname);
			reporto2ourl.append("&operatorName="+operatorName);
			reporto2ourl.append("&loanType="+loanType);
			reporto2ourl.append("&startTime="+startTime);
			reporto2ourl.append("&endTime="+endTime);
			reporto2ourl.append("&stTime="+stTime);	
			reporto2ourl.append("&sendTime="+sendTime);
			reporto2ourl.append("&eendTime="+eendTime);	
			reporto2ourl.append("&eendendTime="+eendendTime);
			reporto2ourl.append("&hostProvince="+hostProvince);
			reporto2ourl.append("&billStatus="+billStatus);
			reporto2ourl.append("&payMentStatus="+payMentStatus);
			}
		pageUrl.append("&pageIndex=");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl.toString());
		paginationInfo.setSelectDataOptions(selectDataOptions);
		Button[] titleButton = new Button[] { ButtonHelper.createOpenButton(null, "/oldo2olike/detail_oldlike/zx?loanapplyNo=") };
		paginationInfo.setTitleButtons(titleButton);
		paginationInfo.setBuildPagingNavigation(true);
//		paginationInfo.setFormats(new Format[]{null,null,null,null,null,null,null,null,new DecimalFormat(",###.00"), null, null});
		paginationInfo.setFirstRenderColumnIndex(1);
		
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("oldO2oLikeForm", oldO2oLikeForm);
		ViewContext.put("reporto2ourl", reporto2ourl.toString());
		ViewContext.put("O2OstampUseRequestSavePre", O2OstampUseRequestSavePre);
		return "/oldo2olike/zx/list";
	}

	
	
	@RequestMapping(value="/ns",method=RequestMethod.GET)
	public String searchns(OldO2oLikeForm oldO2oLikeForm) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "ns_liebiao");
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		ViewContext.put("ActOrgEntitys", orgProvince);
		oldO2oLikeForm.setPageSize(BaseUtils.PAGE_SIZE);
		List<User> users=sysOrgService.checkDataPermission(UserHolder.getUser().getNo());
		String no="";
		if (users!=null) {
			for (User user : users) {
				no+=user.getNo()+",";
			}
		}
		if (!"".equals(no)) {
			if (",".equals(no.substring(no.length()-1, no.length()))) {
				no=no.substring(0, no.length()-1);
			}
		}
		logger.info("userno={}", no);
		oldO2oLikeForm.setPartnerId(no);
		PageResult<Object[]> pageResult = OldO2oLikeService.findNSByPage(oldO2oLikeForm);
		String[] titles = {"贷款单号", "借款人", "申请金额(万元)","审批金额(万元)", "贷款类型","信贷经理", "经营平台","省区", "申请状态","单据状态", "缴纳状态", 
			"创建时间","提交时间","结束时间"};//,"开始时间" ,"结束时间"
		SelectDataOption[] selectDataOptions = {null,  null, null,null,new SelectDataOption("OTO_LOAN_TYPE"),null, null, null, 
				new SelectDataOption("SQZT"), new SelectDataOption("LCZT"), new SelectDataOption("OTO_BZJ_GLF"), null, null, null, null, null
				};
		StringBuffer pageUrl=new StringBuffer("/oldo2olike/ns");
		StringBuffer reporto2ourl = new StringBuffer("/oldo2olike/ns/download");
		if(oldO2oLikeForm!=null){
			String billCode=oldO2oLikeForm.getBillCode()==null?"":oldO2oLikeForm.getBillCode();
			String billStatus=oldO2oLikeForm.getBillStatus()==null?"":oldO2oLikeForm.getBillStatus();
			String loadName=oldO2oLikeForm.getLoadName()==null?"":oldO2oLikeForm.getLoadName();
			String userSurname=oldO2oLikeForm.getUserSurname()==null?"":oldO2oLikeForm.getUserSurname();
			String operatorName=oldO2oLikeForm.getOperatorName()==null?"":oldO2oLikeForm.getOperatorName();
			String loanType=oldO2oLikeForm.getLoanType()==null?"":oldO2oLikeForm.getLoanType();
			String startTime=oldO2oLikeForm.getStartTime()==null?"":oldO2oLikeForm.getStartTime();
			String endTime=oldO2oLikeForm.getEndTime()==null?"":oldO2oLikeForm.getEndTime();
			String stTime=oldO2oLikeForm.getStTime()==null?"":oldO2oLikeForm.getStTime();
			String sendTime=oldO2oLikeForm.getSendTime()==null?"":oldO2oLikeForm.getSendTime();
			String eendTime=oldO2oLikeForm.getEendTime()==null?"":oldO2oLikeForm.getEendTime();
			String eendendTime=oldO2oLikeForm.getEendendTime()==null?"":oldO2oLikeForm.getEendendTime();
			String hostProvince=oldO2oLikeForm.getHostProvince()==null?"":oldO2oLikeForm.getHostProvince();
			String payMentStatus=oldO2oLikeForm.getPayMentStatus()==null?"":oldO2oLikeForm.getPayMentStatus();
			
			pageUrl.append("?billCode="+billCode);
			pageUrl.append("&loadName="+loadName);
			pageUrl.append("&userSurname="+userSurname);
			pageUrl.append("&operatorName="+operatorName);
			pageUrl.append("&loanType="+loanType);
			pageUrl.append("&startTime="+startTime);
			pageUrl.append("&endTime="+endTime);
			pageUrl.append("&stTime="+stTime);
			pageUrl.append("&sendTime="+sendTime);
			pageUrl.append("&eendTime="+eendTime);
			pageUrl.append("&eendendTime="+eendendTime);
			pageUrl.append("&hostProvince="+hostProvince);
			pageUrl.append("&billStatus="+billStatus);
			pageUrl.append("&payMentStatus="+payMentStatus);
			
			reporto2ourl.append("?billCode="+billCode);
			reporto2ourl.append("&loadName="+loadName);
			reporto2ourl.append("&userSurname="+userSurname);
			reporto2ourl.append("&operatorName="+operatorName);
			reporto2ourl.append("&loanType="+loanType);
			reporto2ourl.append("&startTime="+startTime);
			reporto2ourl.append("&endTime="+endTime);
			reporto2ourl.append("&stTime="+stTime);	
			reporto2ourl.append("&sendTime="+sendTime);
			reporto2ourl.append("&eendTime="+eendTime);	
			reporto2ourl.append("&eendendTime="+eendendTime);
			reporto2ourl.append("&hostProvince="+hostProvince);
			reporto2ourl.append("&billStatus="+billStatus);
			reporto2ourl.append("&payMentStatus="+payMentStatus);
			}
		pageUrl.append("&pageIndex=");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl.toString());
		paginationInfo.setSelectDataOptions(selectDataOptions);
		Button[] titleButton = new Button[] { ButtonHelper.createOpenButton(null, "/oldo2olike/detail_oldlike/ns?loanapplyNo=") };
		paginationInfo.setTitleButtons(titleButton);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFormats(new Format[]{null,null,new DecimalFormat(",###.00"), new DecimalFormat(",###.00"),null,null,null,null,null, null});
		paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("oldO2oLikeForm", oldO2oLikeForm);
		ViewContext.put("reporto2ourl", reporto2ourl.toString());
		ViewContext.put("O2OstampUseRequestSavePre", O2OstampUseRequestSavePre);
		return "/oldo2olike/ns/list";
	}
	
	/**
	 * 财务审核
	 * @param oldO2oLikeForm
	 * @return
	 */
	@RequestMapping(value="/cwsh",method=RequestMethod.GET)
	public String searchcwsh(OldO2oLikeForm oldO2oLikeForm) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "cwsh_liebiao");
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		ViewContext.put("ActOrgEntitys", orgProvince);
		oldO2oLikeForm.setPageSize(BaseUtils.PAGE_SIZE);
		
		List<User> users=sysOrgService.checkDataPermission(UserHolder.getUser().getNo());
		String no="";
		if (users!=null) {
			for (User user : users) {
				no+=user.getNo()+",";
			}
		}
		if (!"".equals(no)) {
			if (",".equals(no.substring(no.length()-1, no.length()))) {
				no=no.substring(0, no.length()-1);
			}
		}
		logger.info("userno={}", no);
		oldO2oLikeForm.setXdjlNo(no);
		
		oldO2oLikeForm.setPartnerId(getParatnerId(oldO2oLikeForm.getPartnerName(), oldO2oLikeForm.getBrandName()));
		PageResult<Object[]> pageResult = OldO2oLikeService.findCWSHByPage(oldO2oLikeForm);
		String[] titles = {"贷款单号", "借款人姓名", "贷款类型", "信贷经理", "经营平台","省区","客户名称", "申请状态","单据状态",
			"开始时间","结束时间" };
		SelectDataOption[] selectDataOptions = {null,  null, new SelectDataOption("OTO_LOAN_TYPE"), null,null,null, null,new SelectDataOption("SQZT"),  null, null, null
				};
		StringBuffer pageUrl=new StringBuffer("/oldo2olike/cwsh");
		StringBuffer reporto2ourl = new StringBuffer("/oldo2olike/cwsh/download");
		if(oldO2oLikeForm!=null){
			String billCode=oldO2oLikeForm.getBillCode()==null?"":oldO2oLikeForm.getBillCode();
			String billStatus=oldO2oLikeForm.getBillStatus()==null?"":oldO2oLikeForm.getBillStatus();
			String loadName=oldO2oLikeForm.getLoadName()==null?"":oldO2oLikeForm.getLoadName();
			String userSurname=oldO2oLikeForm.getUserSurname()==null?"":oldO2oLikeForm.getUserSurname();
			String operatorName=oldO2oLikeForm.getOperatorName()==null?"":oldO2oLikeForm.getOperatorName();
			String OldO2oLikeStatus=oldO2oLikeForm.getPayMentStatus()==null?"":oldO2oLikeForm.getPayMentStatus();
			String bankType=oldO2oLikeForm.getBankType()==null?"":oldO2oLikeForm.getBankType();
			String loanType=oldO2oLikeForm.getLoanType()==null?"":oldO2oLikeForm.getLoanType();
			String startTime=oldO2oLikeForm.getStartTime()==null?"":oldO2oLikeForm.getStartTime();
			String endTime=oldO2oLikeForm.getEndTime()==null?"":oldO2oLikeForm.getEndTime();
			String onPlace=oldO2oLikeForm.getOnPlace()==null?"":oldO2oLikeForm.getOnPlace();
			String buybackName=oldO2oLikeForm.getBuybackName()==null?"":oldO2oLikeForm.getBuybackName();
			String regionalName=oldO2oLikeForm.getRegionalName()==null?"":oldO2oLikeForm.getRegionalName();
			String brandName=oldO2oLikeForm.getBrandName()==null?"":oldO2oLikeForm.getBrandName();
			String partnerName=oldO2oLikeForm.getPartnerName()==null?"":oldO2oLikeForm.getPartnerName();
			String hostProvince=oldO2oLikeForm.getHostProvince()==null?"":oldO2oLikeForm.getHostProvince();
			String eendTime=oldO2oLikeForm.getEendTime()==null?"":oldO2oLikeForm.getEendTime();
			String eendendTime=oldO2oLikeForm.getEendendTime()==null?"":oldO2oLikeForm.getEendendTime();
			pageUrl.append("?billCode="+billCode);
			pageUrl.append("&loadName="+loadName);
			pageUrl.append("&userSurname="+userSurname);
			pageUrl.append("&operatorName="+operatorName);
			pageUrl.append("&OldO2oLikeStatus="+OldO2oLikeStatus);
			pageUrl.append("&bankType="+bankType);
			pageUrl.append("&loanType="+loanType);
			pageUrl.append("&startTime="+startTime);
			pageUrl.append("&endTime="+endTime);
			pageUrl.append("&onPlace="+onPlace);
			pageUrl.append("&buybackName="+buybackName);
			pageUrl.append("&regionalName="+regionalName);
			pageUrl.append("&brandName="+brandName);
			pageUrl.append("&partnerName="+partnerName);
			pageUrl.append("&hostProvince="+hostProvince);
			pageUrl.append("&eendTime="+eendTime);
			pageUrl.append("&eendendTime="+eendendTime);
			pageUrl.append("&billStatus="+billStatus);
			
			reporto2ourl.append("?billCode="+billCode);
			reporto2ourl.append("&loadName="+loadName);
			reporto2ourl.append("&userSurname="+userSurname);
			reporto2ourl.append("&operatorName="+operatorName);
			reporto2ourl.append("&OldO2oLikeStatus="+OldO2oLikeStatus);
			reporto2ourl.append("&bankType="+bankType);
			reporto2ourl.append("&loanType="+loanType);
			reporto2ourl.append("&startTime="+startTime);
			reporto2ourl.append("&endTime="+endTime);
			reporto2ourl.append("&onPlace="+onPlace);	
			reporto2ourl.append("&buybackName="+buybackName);
			reporto2ourl.append("&regionalName="+regionalName);
			reporto2ourl.append("&brandName="+brandName);
			reporto2ourl.append("&partnerName="+partnerName);
			reporto2ourl.append("&hostProvince="+hostProvince);
			reporto2ourl.append("&eendTime="+eendTime);	
			reporto2ourl.append("&eendendTime="+eendendTime);
			reporto2ourl.append("&billStatus="+billStatus);
			}
		pageUrl.append("&pageIndex=");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl.toString());
		paginationInfo.setSelectDataOptions(selectDataOptions);
		Button[] titleButton = new Button[] { ButtonHelper.createAjaxButton(null, "/oldo2oliker/cwsh_detail?loanapplyNo=") };
		paginationInfo.setTitleButtons(titleButton);
		paginationInfo.setBuildPagingNavigation(true);
		//paginationInfo.setFormats(new Format[]{null,null,null,null,null,null,null,null,null,new DecimalFormat(",###.00"), null, null});
		paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("oldO2oLikeForm", oldO2oLikeForm);
		ViewContext.put("reporto2ourl", reporto2ourl.toString());
		ViewContext.put("O2OstampUseRequestSavePre", O2OstampUseRequestSavePre);
		return "/oldo2olike/cwsh/list";
	}
	
	/**
	 * 面签申报
	 * @param oldO2oLikeForm
	 * @return
	 */
	@RequestMapping(value="/mqsb",method=RequestMethod.GET)
	public String searchmqsb(OldO2oLikeForm oldO2oLikeForm) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "mqsb_liebiao");
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		ViewContext.put("ActOrgEntitys", orgProvince);
		oldO2oLikeForm.setPageSize(BaseUtils.PAGE_SIZE);
		List<User> users=sysOrgService.checkDataPermission(UserHolder.getUser().getNo());
		String no="";
		if (users!=null) {
			for (User user : users) {
				no+=user.getNo()+",";
			}
		}
		if (!"".equals(no)) {
			if (",".equals(no.substring(no.length()-1, no.length()))) {
				no=no.substring(0, no.length()-1);
			}
		}
		logger.info("userno={}", no);
		
		oldO2oLikeForm.setPartnerId(no);
		PageResult<Object[]> pageResult = OldO2oLikeService.findMQSBByPage(oldO2oLikeForm);
		String[] titles = {"贷款单号", "借款人姓名","送审银行", "金额(万元)","审批金额(万元)","信贷经理", "经营平台","省区", "贷款类型", "申请状态","单据状态", "缴纳状态", 
			"创建时间" ,"提交时间","结束时间"};
		SelectDataOption[] selectDataOptions = {null,  null,new SelectDataOption("BANKTYPEO2O"), null,null,null, null, null, new SelectDataOption("OTO_LOAN_TYPE"),
				new SelectDataOption("SQZT"),new SelectDataOption("LCZT"), new SelectDataOption("OTO_BZJ_GLF"), null, null, null
				};
		StringBuffer pageUrl=new StringBuffer("/oldo2olike/mqsb");
		StringBuffer reporto2ourl = new StringBuffer("/oldo2olike/mqsb/download");
		if(oldO2oLikeForm!=null){
			String billCode=oldO2oLikeForm.getBillCode()==null?"":oldO2oLikeForm.getBillCode();
			String billStatus=oldO2oLikeForm.getBillStatus()==null?"":oldO2oLikeForm.getBillStatus();
			String loadName=oldO2oLikeForm.getLoadName()==null?"":oldO2oLikeForm.getLoadName();
			String userSurname=oldO2oLikeForm.getUserSurname()==null?"":oldO2oLikeForm.getUserSurname();
			String operatorName=oldO2oLikeForm.getOperatorName()==null?"":oldO2oLikeForm.getOperatorName();
			String loanType=oldO2oLikeForm.getLoanType()==null?"":oldO2oLikeForm.getLoanType();
			String startTime=oldO2oLikeForm.getStartTime()==null?"":oldO2oLikeForm.getStartTime();
			String endTime=oldO2oLikeForm.getEndTime()==null?"":oldO2oLikeForm.getEndTime();
			String stTime=oldO2oLikeForm.getStTime()==null?"":oldO2oLikeForm.getStTime();
			String sendTime=oldO2oLikeForm.getSendTime()==null?"":oldO2oLikeForm.getSendTime();
			String eendTime=oldO2oLikeForm.getEendTime()==null?"":oldO2oLikeForm.getEendTime();
			String eendendTime=oldO2oLikeForm.getEendendTime()==null?"":oldO2oLikeForm.getEendendTime();
			String hostProvince=oldO2oLikeForm.getHostProvince()==null?"":oldO2oLikeForm.getHostProvince();
			String payMentStatus=oldO2oLikeForm.getPayMentStatus()==null?"":oldO2oLikeForm.getPayMentStatus();
			String bankType=oldO2oLikeForm.getBankType()==null?"":oldO2oLikeForm.getBankType();
			
			pageUrl.append("?billCode="+billCode);
			pageUrl.append("&loadName="+loadName);
			pageUrl.append("&userSurname="+userSurname);
			pageUrl.append("&operatorName="+operatorName);
			pageUrl.append("&loanType="+loanType);
			pageUrl.append("&startTime="+startTime);
			pageUrl.append("&endTime="+endTime);
			pageUrl.append("&stTime="+stTime);
			pageUrl.append("&sendTime="+sendTime);
			pageUrl.append("&eendTime="+eendTime);
			pageUrl.append("&eendendTime="+eendendTime);
			pageUrl.append("&hostProvince="+hostProvince);
			pageUrl.append("&billStatus="+billStatus);
			pageUrl.append("&payMentStatus="+payMentStatus);
			pageUrl.append("&bankType="+bankType);
			
			reporto2ourl.append("?billCode="+billCode);
			reporto2ourl.append("&loadName="+loadName);
			reporto2ourl.append("&userSurname="+userSurname);
			reporto2ourl.append("&operatorName="+operatorName);
			reporto2ourl.append("&loanType="+loanType);
			reporto2ourl.append("&startTime="+startTime);
			reporto2ourl.append("&endTime="+endTime);
			reporto2ourl.append("&stTime="+stTime);	
			reporto2ourl.append("&sendTime="+sendTime);
			reporto2ourl.append("&eendTime="+eendTime);	
			reporto2ourl.append("&eendendTime="+eendendTime);
			reporto2ourl.append("&hostProvince="+hostProvince);
			reporto2ourl.append("&billStatus="+billStatus);
			reporto2ourl.append("&payMentStatus="+payMentStatus);
			reporto2ourl.append("&bankType="+bankType);
			}
		pageUrl.append("&pageIndex=");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl.toString());
		paginationInfo.setSelectDataOptions(selectDataOptions);
		Button[] titleButton = new Button[] { ButtonHelper.createOpenButton(null, "/oldo2olike/detail_oldlike/mqsb?loanapplyNo=") };
		paginationInfo.setTitleButtons(titleButton);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFormats(new Format[]{null,null,null,new DecimalFormat(",###.00"), new DecimalFormat(",###.00"),null,null,null,null,null, null});
		paginationInfo.setFirstRenderColumnIndex(1);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("oldO2oLikeForm", oldO2oLikeForm);
		ViewContext.put("reporto2ourl", reporto2ourl.toString());
		ViewContext.put("O2OstampUseRequestSavePre", O2OstampUseRequestSavePre);
		return "/oldo2olike/mqsb/list";
	}
	
	/**
	 * @Description:
	 *               <p>
	 *               根据查询合作方name或者品牌name查询合作方id
	 *               </p>
	 * @author CXW
	 * @date 2017年2月16日 上午10:40:13
	 * @version V1.0
	 */
	public String getParatnerId(String partnerName, String brandName) {
		StringBuffer partnerIds = new StringBuffer();
		String partnerId = "";
		if (!StringUtils.isEmpty(partnerName) || !StringUtils.isEmpty(brandName)) {
			List<Object[]> data = o2oPartnerService.getPartnerIds(partnerName, brandName);
			if (data != null && data.size() > 0) {
				for (int i = 0; i < data.size(); i++) {
					for (int j = 0; j < data.get(i).length; j++) {
						partnerIds.append("'" + data.get(i)[j] + "',");
					}
				}
			} else {
				partnerId = "-1";
			}
		}
		if (partnerIds.length() > 0)
			partnerId = partnerIds.toString().substring(0, partnerIds.toString().length() - 1);
		return partnerId;
	}
	
	@RequestMapping("/zx/download")
	public void dowanloadZX(OldO2oLikeForm oldO2oLikeForm,HttpServletResponse httpServletResponse, HttpServletRequest request) {
		oldO2oLikeForm.setPageSize(Integer.MAX_VALUE);
		oldO2oLikeForm.setPartnerId(getParatnerId(oldO2oLikeForm.getPartnerName(), oldO2oLikeForm.getBrandName()));
		PageResult<Object[]> pageResult = OldO2oLikeService.findZXByPage(oldO2oLikeForm,"export");
		try {
			String outfile = "征信准入数据.xls";
			String userAgent = request.getHeader("User-Agent");
			byte[] bytes = userAgent.contains("MSIE") ? outfile.getBytes() : outfile.getBytes("UTF-8");
			outfile = new String(bytes, "ISO-8859-1"); // 各浏览器基本都支持ISO编码
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			httpServletResponse.setContentType("application/octet-stream; charset=utf-8");
			DefaultRowWriteHandler defaultRowWriteHandler = new DefaultRowWriteHandler(pageResult.getData());
			ExcelApiHelper.writeHandle(httpServletResponse.getOutputStream(), OldO2oLikeController.class.getResourceAsStream("/excelTemplate/oldlikezx-model.xls"), defaultRowWriteHandler);
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} 
	}
	
	@RequestMapping("/ns/download")
	public void dowanloadNS(OldO2oLikeForm oldO2oLikeForm,HttpServletResponse httpServletResponse, HttpServletRequest request) {
		oldO2oLikeForm.setPageSize(Integer.MAX_VALUE);
		oldO2oLikeForm.setPartnerId(getParatnerId(oldO2oLikeForm.getPartnerName(), oldO2oLikeForm.getBrandName()));
		PageResult<Object[]> pageResult = OldO2oLikeService.findNSByPageExport(oldO2oLikeForm);
		try {
			String outfile = "内审数据.xls";
			String userAgent = request.getHeader("User-Agent");
			byte[] bytes = userAgent.contains("MSIE") ? outfile.getBytes() : outfile.getBytes("UTF-8");
			outfile = new String(bytes, "ISO-8859-1"); // 各浏览器基本都支持ISO编码
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			httpServletResponse.setContentType("application/octet-stream; charset=utf-8");
			DefaultRowWriteHandler defaultRowWriteHandler = new DefaultRowWriteHandler(pageResult.getData());
			ExcelApiHelper.writeHandle(httpServletResponse.getOutputStream(), OldO2oLikeController.class.getResourceAsStream("/excelTemplate/oldlikens-model.xls"), defaultRowWriteHandler);
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		}
	}
	
	@RequestMapping("/cwsh/download")
	public void dowanloadCWSH(OldO2oLikeForm oldO2oLikeForm,HttpServletResponse httpServletResponse, HttpServletRequest request) {
		oldO2oLikeForm.setPageSize(Integer.MAX_VALUE);
		oldO2oLikeForm.setPartnerId(getParatnerId(oldO2oLikeForm.getPartnerName(), oldO2oLikeForm.getBrandName()));
		
		List<User> users=sysOrgService.checkDataPermission(UserHolder.getUser().getNo());
		String no="";
		if (users!=null) {
			for (User user : users) {
				no+=user.getNo()+",";
			}
		}
		if (!"".equals(no)) {
			if (",".equals(no.substring(no.length()-1, no.length()))) {
				no=no.substring(0, no.length()-1);
			}
		}
		logger.info("userno={}", no);
		oldO2oLikeForm.setXdjlNo(no);
		
		PageResult<Object[]> pageResult = OldO2oLikeService.findCWSHByPageExport(oldO2oLikeForm);
		try {
			String outfile = "财务审核数据.xls";
			String userAgent = request.getHeader("User-Agent");
			byte[] bytes = userAgent.contains("MSIE") ? outfile.getBytes() : outfile.getBytes("UTF-8");
			outfile = new String(bytes, "ISO-8859-1"); // 各浏览器基本都支持ISO编码
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			httpServletResponse.setContentType("application/octet-stream; charset=utf-8");
			DefaultRowWriteHandler defaultRowWriteHandler = new DefaultRowWriteHandler(pageResult.getData());
			ExcelApiHelper.writeHandle(httpServletResponse.getOutputStream(), OldO2oLikeController.class.getResourceAsStream("/excelTemplate/oldlikecwsh-model.xls"), defaultRowWriteHandler);
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} 
	}
	
	@RequestMapping("/mqsb/download")
	public void dowanloadMQSB(OldO2oLikeForm oldO2oLikeForm,HttpServletResponse httpServletResponse, HttpServletRequest request) {
		oldO2oLikeForm.setPageSize(Integer.MAX_VALUE);
		oldO2oLikeForm.setPartnerId(getParatnerId(oldO2oLikeForm.getPartnerName(), oldO2oLikeForm.getBrandName()));
		PageResult<Object[]> pageResult = OldO2oLikeService.findMQSBByPageExport(oldO2oLikeForm);
		try {
			String outfile = "面签申报数据.xls";
			String userAgent = request.getHeader("User-Agent");
			byte[] bytes = userAgent.contains("MSIE") ? outfile.getBytes() : outfile.getBytes("UTF-8");
			outfile = new String(bytes, "ISO-8859-1"); // 各浏览器基本都支持ISO编码
			httpServletResponse.reset();
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			httpServletResponse.setContentType("application/octet-stream; charset=utf-8");
			DefaultRowWriteHandler defaultRowWriteHandler = new DefaultRowWriteHandler(pageResult.getData());
			ExcelApiHelper.writeHandle(httpServletResponse.getOutputStream(), OldO2oLikeController.class.getResourceAsStream("/excelTemplate/oldlikens-model.xls"), defaultRowWriteHandler);
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} 
	}
	
	
	/**
	 * 
	 * 
	 * @param showDetailForm
	 * @return
	 */
	@RequestMapping(value = "/detail_oldlike/{detailType}")
	public String showDetail(ShowDetailForm showDetailForm,@PathVariable("detailType") String detailType) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "detail_oldlike_" + detailType);
		O2oLoanapplyEntity loanapply = null;
		User user = UserHolder.getUser();
		ViewContext.put("user", user);
		
		String userZxId="";
		String mateZxId="";
		if (!StringUtil.isEmpty(showDetailForm.getBillCode())) {
			loanapply = o2oloanapplyService.fingByBillCodeDetail(showDetailForm.getBillCode());
			if (loanapply == null) {
				//没有权限返回错误页面
				return "notauthView";
			}
			showDetailForm.setLoanapplyNo(loanapply.getLoanapplyNo());
		}
		loanapply = o2oloanapplyService.findByIdDetail(showDetailForm.getLoanapplyNo());
//		loanapply.setSettleDate(com.eascs.admin.common.utils.StringUtils.parseDate(loanapply.getSettleDate()));
		if (loanapply != null) {//控制数据权限，空则没有权限，不空则有权限
			CreditReport creditReport = creditReportService.queryLoanapplyNo(showDetailForm.getLoanapplyNo(), String.valueOf(StatusContexts.O2O_ZERO));
			O2oLoanUserEntity materEntity = o2oLoanUserService.findSpouseId(loanapply.getLoanId(), showDetailForm.getLoanapplyNo());
			// 查询是否已交保证金、管理费、风险保证金
			ViewContext.put("loanStatus", loanapplyExpandService.queryLoanapplyNo(showDetailForm.getLoanapplyNo()));
			// 审批详情
			String agreeUrl = baseUtils.getApprovalAgreeUrl(loanapply.getLoanapplyNo(), null, SystemModule.SYSTEM_MODULE_O2O);
			O2oLoanUserEntity loanUser = o2oLoanUserService.findById(loanapply.getLoanId(), loanapply.getLoanapplyNo());
			O2oLoanUserEntity loanSorpouseUser = o2oLoanUserService.findSpouseId(loanapply.getLoanId(), loanapply.getLoanapplyNo());
			O2oBankLoanData bankData = o2oLoanService.queryBillCode(loanapply.getBillCode());
			BrandAndPartnerVo brand = o2oBrandService.queryCodeAndName(loanapply.getLoanapplyNo());
			ViewContext.put("bankData", bankData);
			ViewContext.put("loanUser", loanUser);
			ViewContext.put("loanSorpouseUser", loanSorpouseUser);
			ViewContext.put("agreeUrl", agreeUrl);
			ViewContext.put("domain", domain);
			ViewContext.put("materEntity", materEntity);
			ViewContext.put("brand", brand);
			String isNotContinue = null;
			O2oLoanapplyEntity loanapplyEntity = loanDetailService.queryLoanapplyBillCode(loanapply.getLoanapplyNo(), loanapply.getLoanId(), loanapply.getBillCode(), loanapply.getCreateDate());
			if (loanapplyEntity != null) {
				loanapply.setContinueLoanParenNo(loanapplyEntity.getBillCode());
				isNotContinue = "Y";
			}
			// 面签申报通过才能发起贷后检查
			String loanFlg = loanapply.getLoanFlg();

			if (loanFlg != null && "Y".equals(loanFlg) && !"HN".equals(loanapply.getWfType())) {
				Boolean flag = loanCheckServicce.isStartFlow(loanapply.getBillCode());
				if (!flag) {
					ViewContext.put("ableCheck", "true");
				}
			}
			ViewContext.put("isNotContinue", isNotContinue);
			ViewContext.put("loanapply", loanapply);
			ViewContext.put("creditReport", creditReport);
			if (StringUtil.isNotBlank(detailType)
					&& ("zx".equals(detailType) || "ns".equals(detailType) || "mqsb".equals(detailType))) {// 征信、内审、面签申报
				
				if (loanUser != null) {
					userZxId = loanUser.getZxNo();
				}
				if (materEntity != null) {
					mateZxId = materEntity.getZxNo();
				}
			} 
			
			ViewContext.put("userZxId", userZxId);
			ViewContext.put("mateZxId", mateZxId);
			
			String datalistReadonly = "true";
			/*if((StatusContexts.O2O_ZX_END.equals(loanapply.getWfType())  && "zx".equals(detailType))
				||(StatusContexts.O2O_NS_END.equals(loanapply.getWfType()) && "ns".equals(detailType))
					){
				datalistReadonly = "true";
			}
			if("mqsb".equals(detailType)){
				if(	StatusContexts.O2O_NS_END.equals(loanapply.getWfType())  
						||StatusContexts.O2O_SB_BEGIN.equals(loanapply.getWfType())
					) {
					
				}else {
					datalistReadonly = "true";
				}
			}*/
			
			O2oEnterpriseZxEntity O2oEnterpriseZxEntity= o2oEnterpriseZxService.getEntityByloanapply(loanapply.getLoanapplyNo());
			ViewContext.put("datalistReadonly", datalistReadonly);
			ViewContext.put("O2oEnterpriseZxEntity", O2oEnterpriseZxEntity);
			// 贷前还是贷后判断（是否已放款）
			//判断是否有
			O2OSpecialInterview specialInterview =  o2OSpecialInterviewService.fingCLOFlow(loanapply.getLoanapplyNo()); // 特殊面签申报实体类
			ViewContext.put("specialInterview", specialInterview);
			if(StringUtil.isNotBlank(detailType)){
				return "oldo2olike/"+detailType+"/detail";
			}else{
				return "oldo2olike/mqsb/detail";
			}
		} else {//没有权限返回错误页面
			return "notauthView";
		}
	}

	/**
	 * @Title: bc_zxfk
	 * @Description: 征信调查反馈
	 * @author 张庆奇
	 * @param loanapplyNo
	 * @return
	 * @return BaseRestResult<String>
	 * @throws
	 * @date 2018年1月17日 下午2:56:10
	 */
	@RequestMapping("/bc_zxfk")
	public String bc_zxfk(String loanapplyNo){
		O2oLoanapplyEntity loanapply = o2oloanapplyService.findById(loanapplyNo);
		O2oLoanUserEntity	 user=o2oloanapplyService.findLoanUserEntity(loanapplyNo,loanapply.getLoanId());
		O2oLoanUserEntity	 mateUser=o2oLoanUserService.findSpouseId(user.getLoanId(), loanapplyNo);
		O2oLoanUserEntityZx uerEntityZx  = o2oLoadUserZxServiceImpl.getEntityByZxNo(user.getZxNo());
		ViewContext.put("uerEntityZx", uerEntityZx);
		if(mateUser!=null){
			O2oLoanUserEntityZx mateEntityZx  = o2oLoadUserZxServiceImpl.getEntityByZxNo(mateUser.getZxNo());
			ViewContext.put("mateEntityZx", mateEntityZx);
		}
		return "oldo2olike/ns/bc_zxfk";
	}

	
	/**
	 * @Title: bc_dkfk
	 * @Description: 中行贷款反馈
	 * @author 张庆奇
	 * @param loanapplyNo
	 * @return
	 * @return String
	 * @throws
	 * @date 2018年1月19日 下午2:24:31
	 */
	@RequestMapping("/bc_dkfk")
	public String bc_dkfk(String loanapplyNo){
		O2oLoanapplyEntity loanapply = o2oloanapplyService.findById(loanapplyNo);
		O2oLoanUserEntity	 user=o2oloanapplyService.findLoanUserEntity(loanapplyNo,loanapply.getLoanId());
		
		//O2oLoanUserEntityZx uerEntityZx  = o2oLoadUserZxServiceImpl.getEntityByZxNo(user.getZxNo());
		ViewContext.put("uerEntityZx", user);
		
		return "oldo2olike/ns/bc_dkfk";
	}
	
}
